import math
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams

# 设置中文字体
rcParams['font.sans-serif'] = ['SimHei']
rcParams['axes.unicode_minus'] = False

# 将角度转换为弧度再进行计算
a_rad = math.radians(25)
b_rad = math.radians(40)

halfAandB = (a_rad + b_rad)/2
halfAdelB = (a_rad - b_rad)/2

# 计算单个角度的三角函数值
sin_a = math.sin(a_rad)
cos_a = math.cos(a_rad)
sin_b = math.sin(b_rad)
cos_b = math.cos(b_rad)
sin_halfAandB = math.sin(halfAandB)
cos_halfAandB = math.cos(halfAandB)
sin_halfAdelB = math.sin(halfAdelB)
cos_halfAdelB = math.cos(halfAdelB)

# 定义一个极小的数用于浮点数比较
epsilon = 1e-10

print("验证sin(a) + sin(B)", '-' *40)
print(f"sin(a) + sin(b) = {(sin_a + sin_b):.6f}")
print(f"2sin(halfAandB)cos(halfAdelB) = {(2*sin_halfAandB*cos_halfAdelB):.6f}")
print(f"sin(a) + sin(b) = 2sin(halfAandB)cos(halfAdelB) is {abs(sin_a + sin_b - 2*sin_halfAandB*cos_halfAdelB) < epsilon}")

print("验证sin(a) - sin(B)", '-' *40)
print(f"sin(a) - sin(b) = {(sin_a - sin_b):.6f}")
print(f"2cos(halfAandB)sin(halfAdelB) = {(2*cos_halfAandB*sin_halfAdelB):.6f}")
print(f"sin(a) - sin(b) = 2cos(halfAandB)sin(halfAdelB) is {abs(sin_a - sin_b - 2*cos_halfAandB*sin_halfAdelB) < epsilon}")

print("验证cos(a) + cos(B)", '-' *40)
print(f"cos(a) + cos(b) = {(cos_a + cos_b):.6f}")
print(f"2cos(halfAandB)cos(halfAdelB) = {(2*cos_halfAandB*cos_halfAdelB):.6f}")
print(f"cos(a) + cos(b) = 2cos(halfAandB)cos(halfAdelB) is {abs(cos_a + cos_b - 2*cos_halfAandB*cos_halfAdelB) < epsilon}")

print("验证cos(a) - cos(B)", '-' *40)
print(f"cos(a) - cos(b) = {(cos_a - cos_b):.6f}")
print(f"-2sin(halfAandB)sin(halfAdelB) = {(-2*sin_halfAandB*sin_halfAdelB):.6f}")
print(f"cos(a) - cos(b) = -2sin(halfAandB)sin(halfAdelB) is {abs(cos_a - cos_b + 2*sin_halfAandB*sin_halfAdelB) < epsilon}")
